# -*- coding: utf-8 -*-
import tornado.web
import tornado.httpserver
import tornado.options
import tornado.ioloop
from tornado.options import define, options
from settings import settings, mysql, log_file
from urls import urls
import pymysql

define('port', type=int, default=8002, help='Please run')

class Application(tornado.web.Application):
    def __init__(self, *args, **kwargs):
        super(Application, self).__init__(*args, **kwargs)
        # self.db = pymysql.connect(
        #     host = mysql['host'],
        #     user = mysql['user'],
        #     password = mysql['password'],
        #     database = mysql['database'],
        # )
        self.db = pymysql.connect(**mysql)

def main():
    options.logging = 'info'
    options.log_file_prefix = log_file
    tornado.options.parse_command_line()
    app = Application(
        handlers=urls,
        **settings
    )

    httpserver = tornado.httpserver.HTTPServer(app)
    httpserver.listen(options.port)
    tornado.ioloop.IOLoop.current().start()

if __name__ == '__main__':
    main()
